import React from "react";
import { CommonModal } from "@/views/components/CommonModal";
import IconFont from "@/components/IconFont";
import { createSysGoods } from "../../../service";

const ActionCreateSysGoodsModal = (props) => {
	const { onCancel, goodsData, type, query, isSkuType, handleCommand, asyncGetCreatedGoodsPoll } = props;

  const handleOk = async () => {
    const params = {
      ids: goodsData.map(item => item.id),
      operateType: type == '已勾选的未绑定商品' ? 1 : 2,
      type: isSkuType ? 1 : 2,
    }
    if (type != '已勾选的未绑定商品') {
      if (isSkuType) {
        query.skuName = query.skuName ? query.skuName.replace(/，/g, ',').split(',') : query.skuName;
        params.skuParam = query;
      } else {
        query.spuName = query.skuName ? query.skuName.replace(/，/g, ',').split(',') : query.skuName;
        params.spuParam = query;
      }
    }
    const res = await createSysGoods(params);
    onCancel();
    if (res.success) {
      if (res.data.taskId) {
        asyncGetCreatedGoodsPoll(res.data.taskId);
      } else {
        handleCommand("生成系统商品结果", res.data);
      }
    }
  }

	return (
		<>
			<CommonModal
				title={{ title: "生成系统商品" }}
				open={true}
        onCancel={onCancel}
        width={550}
        minHeight={120}
        onOk={handleOk}
			>
        <div style={{ display: "flex", gap: '8px' }}>
          <IconFont type="iconjingshi" style={{ fontSize: 20 }} />
          <span>您确定要根据<span className="common-color13">{type == "已勾选的未绑定商品" ? '已勾选' : '已筛选'}未绑定系统商品的店铺商品</span>生成系统商品/组合吗？（商品编码为空时会取 skuid 填充生成系统商品，已有绑定关系的店铺商品跳过不会处理）</span>
        </div>
			</CommonModal>
		</>
	);
}

export default ActionCreateSysGoodsModal;